;;;
;;;	Author: Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;	All rights reserved.
;;;
;;;	Copyright: 08-15-2013
;;;	   Edited: 08-15-2013
;;;
(DEFUN C:STRIPVERTEX ( / this_vector)
  (ENTMAKE)
  (SETQ this_ss (SSGET '((0 . "POLYLINE"))))
  (SETQ this_ss_len (SSLENGTH this_ss)
        ss_cnt 0
  )
  (WHILE (< ss_cnt this_ss_len)
  (SETQ this_ename (SSNAME this_ss ss_cnt))
  (SETQ this_edata (ENTGET this_ename))
       (PROGN
         (SETQ pline_header
                (LIST
                  (ASSOC 0 this_edata)
                  (ASSOC 67 this_edata)
                  (ASSOC 410 this_edata)
                  (ASSOC 8 this_edata)
                  (CONS 100 "AcDb2dPolyline")
                  (ASSOC 10 this_edata)
                  (ASSOC 70 this_edata)
                  (ASSOC 40 this_edata)
                  (ASSOC 41 this_edata)
                  (ASSOC 71 this_edata)
                  (ASSOC 72 this_edata)
                  (ASSOC 73 this_edata)
                  (ASSOC 74 this_edata)
                  (ASSOC 75 this_edata)
                )
         )
         (SETQ this_edata (ENTGET (ENTNEXT (CDR (ASSOC -1 this_edata)))))
         (SETQ vertex_1 this_edata
               vertex_list (LIST vertex_1)
         )
         (WHILE (NOT (EQ (CDR (ASSOC 0 this_edata)) "SEQEND"))
           (SETQ this_edata (ENTGET (ENTNEXT (CDR (ASSOC -1 this_edata)))))
           (IF (EQ (CDR (ASSOC 0 this_edata)) "VERTEX")
             (PROGN
               (WHILE (AND (EQ (CDR (ASSOC 0 this_edata)) "VERTEX")
                           (IF this_vector NIL (SETQ this_vector (ANGLE (CDR (ASSOC 10 vertex_1))(CDR (ASSOC 10 this_edata)))))
                           (EQUAL this_vector (ANGLE (CDR (ASSOC 10 vertex_1))(CDR (ASSOC 10 this_edata))) 0.1)
                      )
                 (SETQ vertex_2 this_edata)
               )
               (SETQ vertex_list (APPEND vertex_list (LIST vertex_2))
                     this_vector NIL
                     vertex_1 vertex_2
               )
             )
           )
         )
         (COND
           ((AND
               (EQUAL (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CAR vertex_list))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (LAST vertex_list)))))) 0.001);first and last points are equal (as 2d points)
               (EQUAL (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CAR vertex_list))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CADR vertex_list)))))))
                      (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CADR (REVERSE vertex_list)))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (LAST vertex_list)))))))
                      0.001
               );angle of 1st to 2nd point equals angle of 2nd to last point to last point (2d points)
               (EQUAL (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CAR vertex_list))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CADR vertex_list)))))))
                      (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CADR (REVERSE vertex_list)))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CADR vertex_list)))))))
                      0.001
               );angle of 1st to 2nd point equals angle of 2nd to last point to 2nd point (2d points)
             );i.e. 1st and last points are on the line from 2nd to last point to 2nd point (2d points)
            (IF (EQ (BOOLE 1 (CDR (ASSOC 70 pline_header)) 1) 1);original is a closed polyline
              (PROGN ;eliminate first and last points
                (SETQ vertex_list (CDR vertex_list))
                (SETQ vertex_list (REVERSE (CDR (REVERSE vertex_list))))
              )
              (PROGN
                (SETQ pline_header (SUBST (CONS 70 (1+(CDR(ASSOC 70 pline_header))))(ASSOC 70 pline_header)pline_header));make it a closed polyline since the 1st and last points are equal
                (SETQ vertex_list (CDR vertex_list));eliminate the first point
                (SETQ vertex_list (REVERSE (CDR (REVERSE vertex_list))));and eliminate the last point
              )
            ))
           ((AND
               (EQ (BOOLE 1 (CDR (ASSOC 70 pline_header)) 1) 1);original is a closed polyline
               (EQUAL (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (LAST vertex_list))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CAR vertex_list)))))))
                      (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CADR (REVERSE vertex_list)))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (LAST vertex_list)))))))
                      0.001
               );angle of last point to 1st point equals angle of 2nd to last point to last point (2d points)
               (EQUAL (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (LAST vertex_list))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CAR vertex_list)))))))
                      (ANGLE (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CADR (REVERSE vertex_list)))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CAR vertex_list)))))))
                      0.001
               );angle of last point to 1st point equals angle of 2nd to last point to 1st point (2d points)
             );i.e. last point is on the line from 2nd to last point to 1st point (2d points)
             (PROGN ;eliminate last points
               (SETQ old_vl vertex_list)
               (SETQ vertex_list (REVERSE (CDR (REVERSE vertex_list))))
             )
            )
           ((EQUAL (REVERSE (CDR (REVERSE (CDR (ASSOC 10 (CAR vertex_list))))))(REVERSE (CDR (REVERSE (CDR (ASSOC 10 (LAST vertex_list)))))) 0.001);first and last points are equal (as 2d points)
            (IF (EQ (BOOLE 1 (CDR (ASSOC 70 pline_header)) 1) 1);original is a closed polyline
              (SETQ vertex_list (REVERSE (CDR (REVERSE vertex_list)))) ;just eliminate the last point
              (PROGN
                (SETQ pline_header (SUBST (CONS 70 (1+(CDR(ASSOC 70 pline_header))))(ASSOC 70 pline_header)pline_header));make it a closed polyline since the first and last points are equal
                (SETQ vertex_list (REVERSE (CDR (REVERSE vertex_list)))) ;and eliminate the last point
              )
            )
           )
         )
         (ENTMAKE pline_header)
         (FOREACH n vertex_list
           (IF (AND
                 (NOT (EQ n (CAR vertex_list)))
                 (NOT (EQ n (LAST vertex_list)))
                 (OR
                   (EQUAL (ANGLE (CDR(ASSOC 10 (CADR (MEMBER n (REVERSE vertex_list)))))(CDR (ASSOC 10 n)))
                          (ANGLE (CDR (ASSOC 10 n)) (CDR(ASSOC 10 (CADR (MEMBER n vertex_list)))))
                          0.1
                   )
                   (EQUAL (ASSOC 10 n) (ASSOC 10 (CADR (MEMBER n (REVERSE vertex_list)))) 0.001)
                 )
               )
             NIL
             (ENTMAKE
                (LIST
                  (ASSOC 0 n)
                  (ASSOC 67 n)
                  (ASSOC 410 n)
                  (ASSOC 8 n)
                  (CONS 100 "AcDbVertex")
                  (ASSOC 10 n)
                  (ASSOC 40 n)
                  (ASSOC 41 n)
                  (ASSOC 42 n)
                  (ASSOC 70 n)
                  (ASSOC 50 n)
                )
             )
           )
         )
         (ENTMAKE (LIST (CONS 0 "SEQEND")))
       (ENTDEL this_ename)
     )
    (SETQ ss_cnt (1+ ss_cnt))
  )
)
